<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>新闻详情页</title>
		<!--	<link rel="stylesheet" href="../../css/base.css">-->
		<link rel="stylesheet" href="../../css/api.css">
		<link rel="stylesheet" href="../../css/news.css">
		<link rel="stylesheet" href="../../css/base.css">
		<!-- <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"> -->
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<style type="text/css" media="screen">
			.body {
				margin: 0;
				padding: 0;
			}
			#div_newsDetails {
				margin-top: 74px;
				margin-left: 10px;
				margin-right: 10px;
				margin-bottom: 0px;
				/* background: gray; */
			}
			.item_text_title {
				width: 100%;
				margin-top: 20px;
				text-align: center;
				font-size: 16px;
			}
			.max {
				width: 100%;
				height: auto;
			}
			.min {
				width: api .winWidth - 20px;
				height: auto;
			}
			.item_text_bz {
				/*background-color: green;*/
				width: 100%;
				height: 30px;
				text-align: left;
				font-size: 12px;
			}
			p {
				font-size: 14px;
				color: #666666;
			}
		</style>
	</head>
	<body>
		<div class="nav">
			<div class="base_style_color" id='BarAppearance' style="height: 22px;width: 100%; position:fixed; left: 0px;top:0px;"></div>
			<div class="base_navigation_bar base_style_color base_navigation_item_bar" style="position: fixed;left: 0px;top: 22px;">
				<a class="base_left_item" href="#" onclick="back()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
				<span id="newsTitle"></span>
				<a class="base_right_item" onclick="onShareClick()"> <img class="base_item_icon" src="../../image/icon_lan.png"  > </a>
			</div>
		</div>
		<div  id="div_newsDetails" hidden="hidden">
			<span class="item_text_title" id="newsDetailsTitle"> <!-- 我是新闻标题 --> </span>
			<span class="item_text_bz" style="color:gray;" ><span id="newsDetailsCtime"></span> </span>
			<!-- post返回来的内容主体 -->
			<div id="newsDetailsContent" ></div>
		</div>
		<div class="noSign"   id="noData"  hidden="hidden">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure"  id="noNet" hidden="hidden">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button" class="mui-btn mui-btn-outlined" onclick="RefreshData()">
				重新加载
			</button>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/common.js"></script>
	<script src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript">
		//分享的信息
		var url = "http://cfnet.org.cn/approve";
		var title = "长风认证";
		var description = "长风网新闻中心";
		var thumbUrlQQ = "http://ossimg.cfnet.org.cn/img/20170603/112667-1496458368-70714.png";
		var thumbUrlWV = "widget://image/logosmall.png";
		var newsId = "";
		apiready = function() {
		  
			var y = $('.base_navigation_bar').height();
			//44
			var addurl = api.pageParam.news.adurl;
			var type = addurl.indexOf("weixin");
			if (addurl != null && type >= 0) {//有微信连接
				$('#newsTitle').html(api.pageParam.news.title);
				openframe(addurl);
			} else {
				get_data();
			}
			//滚动到顶部
			$('#BarAppearance').click(function() {
				$('html,body').animate({
					scrollTop : '0px'
				}, 200);
			});
			SendBehaviorTrajectoriesNotifi1(0, '岗位新闻详情', '151', api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname, document.title);
		}
		function openframe(url) {
			var y = $('.base_navigation_bar').height() + 22;
			var h = api.winHeight - y;
			api.openFrame({
				name : 'indexLunDetails',
				url : url,
				rect : {
					x : 0,
					y : y,
					w : 'auto',
					h : h
				},
				progress : {//设置进度条类型和样式
					type : 'page',
					color : '#18b4ed'
				},
				reload : true,
				allowEdit : true,
			});
		}

		/*请求数据*/
		function get_data() {
			/*显示提示框*/
			showProgress();
			/*参数*/
			var params = {
				id : api.pageParam.news.id,
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
			};
			cfnetppPOST(url_getApproveDet, params, true, function(data, status) {
				if (status == 'success') {
					$('#noNet').hide();
					if (data.code == 200) {
						// alert(JSON.stringify(data));
						api.hideProgress();
						$('#div_newsDetails').show();
						$('#noData').hide();
						var list = data.data;
						newsId = list.id;
						var kkk = list.title;
						//这个是后改的,因为首页轮播图点击进来的,没法从新闻列表获得title
						$('#newsTitle').html(escape2Html(list.title).replace(/&/g, ''));
						$('#newsDetailsTitle').text(escape2Html(list.title).replace(/&/g, ''));
						$('#newsDetailsCtime').text(getCurrentDate(list.ctime));
						title = escape2Html(list.title).replace(/&/g, '');
						url = api.pageParam.news.appadurl;
						/*设置content主体内容根据json的html代码*/
						var width = api.winWidth - 20;
						var repalce_url = replace_newsDetails(list.content);
						repalce_url = repalce_url.replace(/\\/g, '');
						repalce_url = repalce_url.replace(/max-width:600px;/g, 'width:90%;');
						// repalce_url = repalce_url.replace(/style="font-size: 14px;"/g,'style="font-size: 16px;"');
						repalce_url = repalce_url.replace(/width="576"/g, 'width=90%;');
						repalce_url = repalce_url.replace(/====/g, '');
						repalce_url = repalce_url.replace(/width="553"/g, 'width=90%;');
						repalce_url = repalce_url.replace(/width: 600px; height: 400px;" height="400"/g, 'width=90%;');
						repalce_url = repalce_url.replace(/width="561"/g, "width=" + width + "px");
						repalce_url = repalce_url.replace(/width="563"/g, "width=" + width + "px");
						// alert(JSON.stringify(repalce_url));
						$('#newsDetailsContent').html(repalce_url + "<br><br>");
						// $("#newsDetailsContent img").width("90%");
						setupImage();
						//图片宽高自适应
						/*传入的是带有img标签的html的json字符串,实现了点击图片放大查看*/
						imageTapToSee('#newsDetailsContent');
					} else {
						$('#noData').show();
					}
				} else {
					$('#noNet').show();
				}
			});
		};
		function setupImage() {
			var newWidth = api.winWidth - 20;
			$("img").each(function(i) {
				var oldWith = $(this).width();
				if (oldWith == 0) {
					setTimeout(function() {
						setupImage();
					}, 500);
					return;
				}
				if (oldWith > newWidth) {
					var oldHeight = $(this).height();
					var newHeight = oldHeight * (newWidth / oldWith);
					$(this).width(newWidth);
					$(this).height(newHeight);
				}
			});
		}

		//加载失败点击了刷新按钮
		function RefreshData() {
			$('#noNet').hide();
			//加载最新数据
			get_data();
		}

		function backClick() {
			api.closeWin();
		}

		//分享
		function onShareClick() {
			var message;
			var dialogBox = api.require('dialogBox');
			dialogBox.actionMenu({
				tapClose : true,
				rect : {
					h : 208
				},
				texts : {
					cancel : '取消'
				},
				items : [{
					text : '分享到微信',
					icon : 'widget://image/icon_weixin.png'
				}, {
					text : '分享到朋友圈',
					icon : 'widget://image/icon_pengyouquan.png'
				}, {
					text : '分享到手机QQ',
					icon : 'widget://image/icon_qq.png'
				}, {
					text : '分享到QQ空间',
					icon : 'widget://image/icon_kongjian.png'
				}],
				styles : {
					bg : '#F0F0F0',
					column : 4,
					itemText : {
						color : '#000',
						size : 12,
						marginT : 8
					},
					itemIcon : {
						size : 60
					},
					cancel : {
						// bg:'widget://image/icno_share_buttom.png',
						color : '#535353',
						h : 38,
						size : 14
					}
				}
			}, function(ret) {
				var eventType = ret.eventType;
				//判断类型
				var index = ret.index;
				if (eventType == 'cancel') {//关闭
					dialogBox.close({
						dialogName : 'actionMenu'
					});
					return;
				}
				if (index == 2 || index == 3) {
					var qq = api.require('qq');
					qq.installed(function(ret, err) {
						if (ret.status) {
							if (index == 2) {//qq
								qq.shareNews({
									url : url,
									type : 'QFriend',
									title : title,
									description : description,
									imgUrl : thumbUrlQQ
								}, function(ret, err) {
									dialogBox.close({
										dialogName : 'actionMenu'
									});
									if (ret.status) {
										
											message = title + "分享至QQ";
											sendBuriedPointNotifi(message)
									
										api.toast({
											msg : '分享成功QQ'
										});
									} else {
										if (err.code == -4) {
											api.toast({
												msg : '用户取消分享'
											});
										} else if (err.code == 10000) {
											api.toast({
												msg : 'QQ空间分享不支持文本类型分享'
											});
										} else if (err.code == 10001) {
											api.toast({
												msg : 'QQ空间分享不支持图片类型分享'
											});
										} else if (err.code == 10009) {
											api.toast({
												msg : '当前设备未安装QQ客户端'
											});
										} else {
											api.toast({
												msg : '分享失败QQ'
											});
										}
									}
								});
							} else if (index == 3) {//qq空间
								qq.shareNews({
									url : url,
									type : 'QZone',
									title : title,
									description : description,
									imgUrl : thumbUrlQQ
								}, function(ret, err) {
									dialogBox.close({
										dialogName : 'dialogBox'
									});
									if (ret.status) {
										
											message = title + "分享至QQ空间";
											sendBuriedPointNotifi(message)
										
										api.toast({
											msg : '分享成功QQ空间'
										});
									} else {
										if (err.code == -4) {
											api.toast({
												msg : '用户取消分享'
											});
										} else if (err.code == 10000) {
											api.toast({
												msg : 'QQ空间分享不支持文本类型分享'
											});
										} else if (err.code == 10001) {
											api.toast({
												msg : 'QQ空间分享不支持图片类型分享'
											});
										} else if (err.code == 10009) {
											api.toast({
												msg : '当前设备未安装QQ客户端'
											});
										} else {
											api.toast({
												msg : '分享失败QQ空间'
											});
										}
									}
								});
							}
							return;
						} else {
							dialogBox.close({
								dialogName : 'actionMenu'
							});
							alert("没有安装QQ");
							// $("#passFailCount").show();
							//  $("#title_text").html('没有安装QQ');
						}
					});
				}
				if (index == 0 || index == 1) {
					var wx = api.require('wx');
					wx.isInstalled(function(ret, err) {
						if (ret.installed) {
							if (index == 0) {//微信
								wx.shareWebpage({
									apiKey : '',
									scene : 'session',
									title : title,
									description : description,
									thumb : thumbUrlWV,
									contentUrl : url
								}, function(ret, err) {
									dialogBox.close({
										dialogName : 'actionMenu'
									});
									if (ret.status) {
										
											message = title + "分享至微信好友";
											sendBuriedPointNotifi(message)
										
										api.toast({
											msg : '分享成功微信好友'
										});
									} else {
										api.toast({
											msg : '分享失败微信好友'
										});
									}
								});
							} else if (index == 1) {//朋友圈
								wx.shareWebpage({
									apiKey : '',
									scene : 'timeline',
									title : title,
									description : description,
									thumb : thumbUrlWV,
									contentUrl : url
								}, function(ret, err) {
									dialogBox.close({
										dialogName : 'actionMenu'
									});
									if (ret.status) {
										
											message = title + "分享至朋友圈";
											sendBuriedPointNotifi(message)
										
										api.toast({
											msg : '分享成功朋友圈'
										});
									} else {
										api.toast({
											msg : '分享失败朋友圈'
										});
									}
								});
							}
						} else {
							dialogBox.close({
								dialogName : 'actionMenu'
							});
							alert("没有安装微信");
							//			   $("#passFailCount").show();
							//				       $("#title_text").html('没有安装微信');
						}
					});
				}
			});
		}

		function back() {
			api.closeWin({
			});
			SendBehaviorTrajectoriesNotifi1(1, '岗位新闻详情', '151', api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname, document.title);
		}

		//发送埋点通知
		function sendBuriedPointNotifi(message) {
			var param = new Object();
			var data = new Object();
			param["message"] = message;
			param["uid"]= $api.getStorage('cfnetppuid');
			param["jid"]= $api.getStorage('cfnetppjxid');
			
			if (api.pageParam.Newstype =="HotNews") {
				SendBusinessOperationsLogNotifi('新闻页', '165', param, param, '', data, '热门资讯分享新闻', '165-01');
			} else {
				SendBusinessOperationsLogNotifi('新闻页', '150', param, param, '', data, '认证分享新闻', '150-01');
			}
		}

		////返回是否有url
		//function isurl(){
		//
		//}
	</script>
</html>